﻿using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    /// <summary>
    /// 留言表
    /// </summary>
    public class LeaveDAL
    {
        //留言添加
        public static int leaveAdd(Leave l)
        {
            string sql = "insert into tb_Leave(Content,UserID,Time,Title) values(@Content,@UserID,@Time,@Title)";
            SqlParameter[] para = {
            new SqlParameter("@Content",l.Content),
            new SqlParameter("@UserID",l.UserID),
            new SqlParameter("@Time",l.Time),
            new SqlParameter("@Title",l.Title)
            };
            return SqlDBHelper.ExecuteNonQuery(sql, para);
        }
        //留言查询
        public static DataTable leaveCK()
        {
            string sql = @"select l.LeaveID,l.Title,l.Content,l.Time,u.UserName,l.Reply
                          from tb_Leave l,tb_User u where l.UserID=u.UserID";
            return SqlDBHelper.GetDataTable(sql);
        }
        //留言id查询
        public static DataTable leaveCK(int id)
        {
            string sql = @"select l.LeaveID,l.Title,l.Content,l.Time,u.UserName,l.Reply
                          from tb_Leave l,tb_User u where l.UserID=u.UserID and u.UserID="+id;
            return SqlDBHelper.GetDataTable(sql);
        }
        //美食删除
        public static int leaveDelete(int id)
        {
            string sql = "delete from tb_Leave where LeaveID=" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //留言模糊查询
        public static DataTable leaveMHCK(string sq)
        {
            string sql = @"select l.LeaveID,l.Title,l.Content,l.Time,u.UserName,l.Reply
                        from tb_Leave l,tb_User u where l.UserID=u.UserID "+sq;
            return SqlDBHelper.GetDataTable(sql);
        }
        //留言id查询
        public static DataTable leaveId(int id)
        {
            string sql = @"select l.LeaveID,l.Title,l.Content,l.Time,u.UserName,l.Reply
                        from tb_Leave l,tb_User u where l.UserID=u.UserID and l.LeaveID=" + id;
            return SqlDBHelper.GetDataTable(sql);
        }
        //评价回复
        public static int leaveHf(string hf,int id)
        {
            string sql = "update tb_Leave set Reply=@Reply where LeaveID=" + id;
            SqlParameter[] para = { 
            new SqlParameter("@Reply",hf)
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //查询数据条数
        public static object dataNum()
        {
            string sql = "select count(*) from tb_Leave";
            return SqlDBHelper.ExecuteScalar(sql);
        }
    }
}
